//
//  HMStatusToolBar.swift
//  MyWeibo
//
//  Created by apple on 16/4/21.
//  Copyright © 2016年 apple. All rights reserved.
//

import UIKit

class HMStatusToolBar: UIView {
    
    override init(frame: CGRect) {
        
        super.init(frame: frame)
        
        setupUI()
        
    }
    
    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    //加载控件
    func setupUI(){
        //        backgroundColor = RandomColor
        
        //设置调试背景色
//        backgroundColor = UIColor.orangeColor()
        
        //添加控件
        let retweetBtn = addChildButton("转发", imgNamed: "timeline_icon_retweet")
        let commentBtn = addChildButton("评论", imgNamed: "timeline_icon_comment")
        let likeBtn = addChildButton("赞", imgNamed: "timeline_icon_unlike")
        
        //添加竖线
        let sp1 = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        let sp2 = UIImageView(image: UIImage(named: "timeline_card_bottom_line"))
        addSubview(sp1);addSubview(sp2)
        
        //设置约束
        
        retweetBtn.snp_makeConstraints { (make) -> Void in
            
            make.leading.top.bottom.equalTo(self)
            
            make.width.equalTo(commentBtn)
        }
        
        commentBtn.snp_makeConstraints { (make) -> Void in
            
            make.leading.equalTo(retweetBtn.snp_trailing)
            make.width.equalTo(likeBtn)
            make.top.bottom.equalTo(self)
            
        }
        likeBtn.snp_makeConstraints { (make) -> Void in
            
            make.trailing.top.bottom.equalTo(self)
            make.leading.equalTo(commentBtn.snp_trailing)
            make.width.equalTo(retweetBtn)
            
        }
        sp1.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(retweetBtn.snp_trailing)
            make.centerY.equalTo(self)
        }
        
        sp2.snp_makeConstraints { (make) -> Void in
            make.centerX.equalTo(commentBtn.snp_trailing)
            make.centerY.equalTo(self)
        }
    }
    

//创建方法添加按钮
private func addChildButton(title: String, imgNamed: String) -> UIButton{
    //创建一个button
    let button = UIButton(textColor: UIColor.darkGrayColor(), fontSize: 14)
    //设置button显示的图片
    button.setBackgroundImage(UIImage(named: imgNamed), forState: UIControlState.Normal)
    
    //设置button字体
    button.setTitle(title, forState: UIControlState.Normal)
    
    // 设置不同状态下的背景图片
    button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background_highlighted"), forState: UIControlState.Highlighted)
    button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"),
        forState: UIControlState.Normal)
    addSubview(button)
    
    return button
}

}
